class TimelinesController < ApplicationController
  # GET /timelines
  # GET /timelines.xml
  def index
  @timelines = Timeline.all.paginate(:page => params[:page],:per_page =>3)
 
    respond_to do |format|
      format.html  { render :layout => 'timelines.html'}
      format.fbml { render :layout => 'timelines.fbml'}
 
    end
  end

  # GET /timelines/1
  # GET /timelines/1.xml
  def show
    @events=	@facebook_user.events
    @timeline = Timeline.find(params[:id])

  @timeline_events=   @timeline.timeline_events.paginate(:page => params[:page],:per_page =>5)
    respond_to do |format|
      format.html { render :layout => 'show_timeline' }
      format.xml  { render :xml => @timeline }
    end
  end

  # GET /timelines/new
  # GET /timelines/new.xml
  def new
    @timeline = Timeline.new

    respond_to do |format|

      format.html  { render :layout => 'timelines.html'}
      format.fbml { render :layout => 'timelines.fbml'}
      format.xml  { render :xml => @timeline }
    end
  end

  # GET /timelines/1/edit
  def edit
    @timeline = Timeline.find(params[:id])
  end

  # POST /timelines
  # POST /timelines.xml
  def create
    @timeline = Timeline.new(params[:timeline])

    respond_to do |format|
      if @timeline.save
        flash[:notice] = 'Timeline was successfully created.'
        format.html { redirect_to(@timeline) }
        format.fbml {render :action => "show"}
        format.xml  { render :xml => @timeline, :status => :created, :location => @timeline

        }
      else
        format.html { render :action => "new" }
       format.fbml { render :action => "new" }

        format.xml  { render :xml => @timeline.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /timelines/1
  # PUT /timelines/1.xml
  def update
    @timeline = Timeline.find(params[:id])

    respond_to do |format|
      if @timeline.update_attributes(params[:timeline])
        flash[:notice] = 'Timeline was successfully updated.'
        format.html { redirect_to(@timeline) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @timeline.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /timelines/1
  # DELETE /timelines/1.xml
  def destroy
    @timeline = Timeline.find(params[:id])
    @timeline.destroy

    respond_to do |format|
      format.html { redirect_to(timelines_url) }
      format.xml  { head :ok }
    end
  end

   def show_new
    @events=	@facebook_user.events
    @timeline = Timeline.find(params[:id])

  @timeline_events=   @timeline.timeline_events.paginate(:page => params[:page],:per_page =>5)
    respond_to do |format|
      format.html { render :layout => 'show_timeline' }
      format.xml  { render :xml => @timeline }
    end
  end



end
